<template>
    <transition
        :css='false'
        @enter='enter'
        @leave='leave'
        >
        <div class="mini_player" v-show="this.isShowMiniPlayer">
            <div class="player-warpper">
                <div class="player-left" @click="showNormalPlayer">
                    <img :src="currentSong.picUrl" alt="" ref="cd">
                    <div class="player-title">
                        <h3>{{currentSong.name}}</h3>
                        <p>{{currentSong.singer}}</p>
                    </div>
                </div>
                <div class="player-right">
                    <div class="play" @click="play" ref="play"></div>
                    <div class="list" @click.stop="showList"></div>
                </div>
            </div>
        </div>
    </transition>
</template>

<script>
import { mapActions, mapGetters } from 'vuex'
import Velocity from 'velocity-animate'
import 'velocity-animate/velocity.ui'
export default {
  name: 'MiniPlayer',
  methods: {
    ...mapActions([
      'setFullScreen',
      'setMiniScreen',
      'setIsPlayer',
      'setListScreen'
    ]),
    showList () {
      this.setListScreen(true)
    },
    showNormalPlayer () {
      this.setFullScreen(true)
      this.setMiniScreen(false)
    },
    enter (el, done) {
      Velocity(el, 'transition.shrinkIn', { duration: 500 }, function () {
        done()
      })
    },
    leave (el, done) {
      Velocity(el, 'transition.shrinkOut', { duration: 500 }, function () {
        done()
      })
    },
    play () {
      this.setIsPlayer(!this.isPlaying)
    }
  },
  computed: {
    ...mapGetters([
      'isShowMiniPlayer',
      'isPlaying',
      'currentSong'
    ])
  },
  watch: {
    isPlaying (newValue, oldValue) {
      newValue ? this.$refs.play.classList.add('active') : this.$refs.play.classList.remove('active')
      newValue ? this.$refs.cd.classList.add('active') : this.$refs.cd.classList.remove('active')
    }
  }
}
</script>

<style scoped lang='scss'>
@import "../../assets/css/variable";
@import "../../assets/css/mixin";
.mini_player{
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 150px;
    .player-warpper{
         @include bg_color();
        display: flex;
        justify-content: space-between;
        width: 100%;
        height: 100%;
        align-items: center;
        .player-left{
            display: flex;
            padding-left: 30px;
            img{
                width: 140px;
                height: 140px;
                border-radius: 50%;
                box-sizing: border-box;
                margin-right: 20px;
                border: 20px solid #000;
                animation: sport 30s linear infinite;
                animation-play-state: paused;
                position: relative;
                top: -20px;
                &.active{
                      animation-play-state: running;
                }
            }
            .player-title{
                display: flex;
                flex-direction: column;
                // align-items: center;
                justify-content: center;
                h3{
                    @include font_size($font_medium);
                    @include font_color();
                }
                p{
                    @include font_size($font_medium_s);
                    @include font_color();
                }
            }
        }
        .player-right{
            display: flex;
            align-items: center;
            .play{
                width: 84px;
                height: 84px;
                @include bg_img('../../assets/images/play');
                &.active{
                  @include bg_img('../../assets/images/pause')
              }
            }
            .list{
                width: 120px;
                height: 120px;
                @include bg_img('../../assets/images/list')
            }
        }
    }

}
@keyframes sport{
  from{
    transform: rotate(0deg)
  }
  to{
    transform: rotate(360deg)
  }
}
</style>
